package vn.lumi.smarthome.io.model;

import java.util.ArrayList;

import android.R.integer;

public class Device {
	
//	public static final int DEVICE_TYPE_ONOFF=0;
//	public static final int DEVICE_TYPE_VALUECHANGE=DEVICE_TYPE_ONOFF+1;
//	public static final int DEVICE_TYPE_CEILING=DEVICE_TYPE_VALUECHANGE+1;
//	public static final int DEVICE_TYPE_NONGLANH=DEVICE_TYPE_CEILING+1;
//	public static final int DEVICE_TYPE_AIR_CONDITIONER=DEVICE_TYPE_NONGLANH+1;
//	public static final int DEVICE_TYPE_BLIND_HORIZONTAL=DEVICE_TYPE_AIR_CONDITIONER+1;
//	public static final int DEVICE_TYPE_BLIND_VERTICAL=DEVICE_TYPE_BLIND_HORIZONTAL+1;
//	public static final int DEVICE_TYPE_ROLLING_DOORS=DEVICE_TYPE_BLIND_VERTICAL+1;
	
	public static final int DEVICE_TYPE_LIGHT=1;
	public static final int DEVICE_TYPE_DIMMER=2;
	public static final int DEVICE_TYPE_HOR_BLIND=3;
	public static final int DEVICE_TYPE_VER_BLIND=4;
	public static final int DEVICE_TYPE_AIRCON=5;
	public static final int DEVICE_TYPE_HEATER=6;
	public static final int DEVICE_TYPE_RGB=7;
	public static final int DEVICE_TYPE_FAN=8;
	public static final int DEVICE_TYPE_PIR=9;
	public static final int DEVICE_TYPE_ROLL_DOOR=10;
	
	public static final int DEVICE_STATE_RGB_OFF = Math.abs(0x010101); //r=1 g=1 b=1
	public static final int DEVICE_STATE_RGB_ON = Math.abs(0xA0A0A0); //r = g= b= 0xA0

	public static final int DEVICE_STATE_CONTROL_YES = 1;
	public static final int DEVICE_STATE_CONTROL_NO = 0;
	
	public static final int DEVICE_STATE_DEVICE_ON = 2;
	public static final int DEVICE_STATE_DEVICE_OFF = 1;
	public static final int DEVICE_STATE_DEVICE_REMOVED = 0;
	
	public static final int DEVICE_STATE_BLIND_CMD__LEFT = 0x11;
	public static final int DEVICE_STATE_BLIND_CMD_STOP = 0x10;
	public static final int DEVICE_STATE_BLIND_CMD_RIGHT = 0x12;
	public static final int DEVICE_STATE_BLIND_STATE_OPENNING = 0x0A;
	public static final int DEVICE_STATE_BLIND_STATE_CLOSING = 0x0B;
	public static final int DEVICE_STATE_BLIND_STATE_STOPPED = 0x00;
	public static final int DEVICE_STATE_BLIND_MAX_LEVEL = 8;
	public static final int DEVICE_STATE_BLIND_LEVEL_2 = 2;
	public static final int DEVICE_STATE_BLIND_LEVEL_3 = 3;
	public static final int DEVICE_STATE_BLIND_LEVEL_4 = 4;
	public static final int DEVICE_STATE_BLIND_LEVEL_5 = 5;
	public static final int DEVICE_STATE_BLIND_LEVEL_6 = 6;
	public static final int DEVICE_STATE_BLIND_LEVEL_7 = 7;
	public static final int DEVICE_STATE_BLIND_MIN_LEVEL = 1;
	
	public static final int DEVICE_STATE_DIMMER_MAX_LEVEL = 8;
	public static final int DEVICE_STATE_DIMMER_ON = DEVICE_STATE_DIMMER_MAX_LEVEL;
	public static final int DEVICE_STATE_DIMMER_OFF = 1;
	
	public static final int DEVICE_STATE_FAN_MAX_LEVEL = 4;
	public static final int DEVICE_STATE_FAN_ON = DEVICE_STATE_FAN_MAX_LEVEL;
	public static final int DEVICE_STATE_FAN_OFF = 1;
	
	
	private int id;
	private int type_id;
	private int room_id;
	private String name;
	private int state_id;
	private boolean isControl=false;
	
	
	private DeviceState deviceState;
	
	private ArrayList<Schedule> schedules = new ArrayList<Schedule>();
	
	/**
	 * Duoc su dung khi them + sua canh
	 */
	private boolean isTurnOn=false;
	
	/**
	 * Duoc su dung khi them + sua canh
	 */
	private boolean isSelected=false;
	
	public Device(Device dev){
		this.deviceState = new DeviceState(dev.getDeviceState());
		this.id = dev.id;
		this.isControl = dev.isControl;
		this.isSelected = dev.isSelected;
		this.isTurnOn = dev.isTurnOn;
		this.name = dev.name;
		this.room_id = dev.room_id;
		this.state_id = dev.state_id;
		this.type_id = dev.type_id;
	}
	
	public Device(int id, int type_id, int room_id, String name, int state_id,DeviceState state,boolean isControl) {
		super();
		this.id = id;
		this.type_id = type_id;
		this.room_id = room_id;
		this.name = name;
		this.state_id = state_id;
		deviceState=state;
		this.isControl=isControl;
		this.isSelected = false;
	}
	public Device() {
	}
	
	public boolean isTurnOn() {
		return isTurnOn;
	}
	public void setTurnOn(boolean isTurnOn) {
		this.isTurnOn = isTurnOn;
	}
	public boolean isSelected() {
		return isSelected;
	}
	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}
	
	public boolean isControl() {
		return isControl;
	}
	public void setControl(boolean isControl) {
		this.isControl = isControl;
	}
	public DeviceState getDeviceState() {
		return deviceState;
	}
	public void setDeviceState(DeviceState deviceState) {
		this.deviceState = deviceState;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getType_id() {
		return type_id;
	}
	public void setType_id(int type_id) {
		this.type_id = type_id;
	}
	public int getRoom_id() {
		return room_id;
	}
	public void setRoom_id(int room_id) {
		this.room_id = room_id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getState_id() {
		return state_id;
	}
	public void setState_id(int state_id) {
		this.state_id = state_id;
	}
	public void setSchedule(Schedule schedule){
		schedules.add(schedule);
	}
	public Schedule getSchedule(int index){
		return schedules.get(index);
	}
	public boolean isEmptySchedule(){
		return schedules.isEmpty();
	}
	public int getCountSchedule(){
		return schedules.size();
	}
	public interface OnControlDeviceListener{
		void onControlNormalDevice(Device[] device, int[] value);
		void onControlRGB(Device[] dev, int[] state);
	}
	
	public static enum TYPE{
		LIGHT
	}
	
	/**
	 * Luu y dac biet: Type cua device phai bat dau=0, vi trong phan adapter co yeu cau: getItemViewType< getViewTypeCount
	 */
	public static final int NUM_LAYOUT_TYPE=4;
	public static final int TYPE_LAYOUT_ONOFF=0;
	public static final int TYPE_LAYOUT_DIMMER=TYPE_LAYOUT_ONOFF+1;
	public static final int TYPE_LAYOUT_BLIND=TYPE_LAYOUT_DIMMER+1;
	public static final int TYPE_LAYOUT_RGB=TYPE_LAYOUT_BLIND+1;
	
	
	public static int getLayoutType(int type){
		switch (type) {
		case DEVICE_TYPE_AIRCON:
		case DEVICE_TYPE_HEATER:
		case DEVICE_TYPE_LIGHT:
		return TYPE_LAYOUT_ONOFF;
		
		case DEVICE_TYPE_FAN:
		case DEVICE_TYPE_DIMMER:
		return TYPE_LAYOUT_DIMMER;
		
		case DEVICE_TYPE_HOR_BLIND:
		return TYPE_LAYOUT_BLIND;
		
		case DEVICE_TYPE_RGB:
		return TYPE_LAYOUT_RGB;

		default:
			return 0;
		}
	}
	
}

